package system;
import java.sql.*;
public class getAnswer{
	String testid,studentid;
	
	public void setTestId(String tid){
		testid=tid;
	}
	public String getTestId(){
		return testid;
	}
	
	public void setStudentId(String sid){
		studentid=sid;
	}
	public String getStudentId(){
		return studentid;
	}
	
	public String[] getSingleAnswer(String questionid){
		String[] singleAnswer=new String[2];
		Connection con;
	    Statement sql;
	    ResultSet rs;
	    try{
	    	Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
	    	}
	    catch(Exception e){}
   
        try{
		String uri = "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=test_system";
		String user = "sa";
		String password = "sa";
		con=DriverManager.getConnection(uri,user,password);
		sql=con.createStatement();
		rs=sql.executeQuery("select student_answer,true_or_false from student_question_single_selection where student_id='"+studentid+"' and test_id='"+testid+"' and question_id='"+questionid+"'");
		if(rs.next()){
			singleAnswer[0]=rs.getString(1);
			singleAnswer[1]=rs.getString(2);		
		}
		con.close();
	    } catch(SQLException e1){}
	    return singleAnswer;
	}
	
	public String[] getMultipleAnswer(String questionid){
		String[] multipleAnswer=new String[5];
		
		Connection con;
	    Statement sql;
	    ResultSet rs;
	    try{
	    	Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
	    	}
	    catch(Exception e){}
   
        try{
		String uri = "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=test_system";
		String user = "sa";
		String password = "sa";
		con=DriverManager.getConnection(uri,user,password);
		sql=con.createStatement();
		rs=sql.executeQuery("select student_answer_A,student_answer_B,student_answer_C,student_answer_D,true_or_false from student_question_multiple_selection where student_id='"+studentid+"' and test_id='"+testid+"' and question_id='"+questionid+"'");
		if(rs.next()){
			for(int i=0;i<5;i++){
				multipleAnswer[i]=rs.getString(i+1);
				}		
		}
		con.close();
	    } catch(SQLException e1){}
	    return multipleAnswer;
	}
	
	public String[] getSubjectAnswer(String questionid){
		String[] subjectAnswer=new String[2];
		
		Connection con;
	    Statement sql;
	    ResultSet rs;
	    try{
	    	Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
	    	}
	    catch(Exception e){}
   
        try{
		String uri = "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=test_system";
		String user = "sa";
		String password = "sa";
		con=DriverManager.getConnection(uri,user,password);
		sql=con.createStatement();
		rs=sql.executeQuery("select student_answer,true_or_false from student_question_subjective_topic where student_id='"+studentid+"' and test_id='"+testid+"' and question_id='"+questionid+"'");
		if(rs.next()){
			subjectAnswer[0]=rs.getString(1);
			subjectAnswer[1]=rs.getString(2);		
		}
		con.close();
	    } catch(SQLException e1){}
	    return subjectAnswer;
	}
		
}